#pragma once

#include <stdio.h>
#include <stdlib.h>
#include <sstream>

#include "IOUnit.h"
#include "Monobit.h"
#include "BlockFrequency.h"
#include "Runs.h"
#include "LongestRunOfOnes.h"
#include "BinaryMatrixRank.h"
#include "Dft_spectral.h"
#include "NonOverlappingTemplateMatching.h"
#include "OverlappingTemplateMatching.h"
#include "Universal.h"
#include "LinearComplexity.h"

#define NUMBER_OF_PRN_DEFAULT 100
//#define OUTPUTPATH_DEFAULT "E://HTW//master//projekt krypto//projekt-krypto-14//nist_testsuite//Debug//output.txt"
#define OUTPUTPATH_DEFAULT ".//aes-128-ofb"


static const int MONOBIT_CODE = 0x01;
static const int FREQ_CODE = 0x02;
static const int RUNS_CODE = 0x04;
static const int LONGESTRUN_CODE = 0x08;
static const int MATRIX_CODE = 0x10;
static const int FFT_CODE = 0x20;
static const int NONOVERLAPPING_CODE = 0x40;
static const int OVERLAPPING_CODE = 0x80;
static const int UNIVERSAL_CODE = 0x100;
static const int LINEARCOMPLEX_CODE = 0x200;
static const int SERIAL_CODE = 0x400;
static const int ENTROPY_CODE = 0x800;
static const int SUMS_CPDE = 0x1000;
static const int EXCURSION_CODE = 0x2000;
static const int VARIANT_CODE = 0x4000;
static const int ALL_CODE = 0x7FFF;



class Control
{

public:
	static Control* getInstance()
	{
		if (singleControl == NULL)
			singleControl = new Control();

		return singleControl;
	}

	~Control()
	{
		delete this->ioUnit;
	};


	void start(int argc, char** argv);
	void initTests(bool* bitArray, int bitArraySize);

	int getBitArraySize(){ return this->bitArraySize; }
	int readParameters(int argc, char** argv);


protected:
	Control()
	{
		this->ioUnit = new IOUnit();
		fileName = NULL;
		offset = 0;

		for (int i = 0; i < 15; i++)
		{
			testPass[i] = false;
		}
	};


private:

	static Control* singleControl;

	//Class for reading the testdata from a file
	IOUnit* ioUnit;

	//Classes which implement the different nist tests
	Monobit* monobitTest;
	BlockFrequency* blockfrequencyTest;
	Runs* runsTest;
	LongestRunOfOnes* longestRunOfOnesTest;
	BinaryMatrixRank* binaryMatrixRankTest;

	Dft_spectral* dftSpectralTest;
	NonOverlappingTemplateMatching* nonOverlappingTemplateMatchingTest;
	OverlappingTemplateMatching* overlappingTemplateMatchingTest;

	Universal* universalTest;
	LinearComplexity* linearTest;


	std::vector<short>* bitVector;// testdata as a bool array from IOUnit
	char* fileName;
	bool* bitArray;
	int bitArraySize;
	int bitsToTest;
	int offset;
	bool inputOK;

	void convertVector_to_Array();

	bool testPass[15];



};


